<form action="{:sysuri()}" method="post" data-auto="true" class="layui-form layui-card" data-table-id="PlatformTable">

    <div class="layui-card-body padding-left-40 layui-col-space10">

        {include file='search' , type="form"}
        <div class="layui-col-md12">
            <label class="layui-form-label">{:lang("管理员昵称")}:</label>
            <div class="layui-input-block">

                <input name="nickname" value='{$vo.nickname}' required class="layui-input" placeholder="{:lang('请输入管理员昵称')}">
            </div>
        </div>

        <div class="layui-col-md12">
            <label class="layui-form-label">{:lang('身份')}</label>
            <div class="layui-input-block">
                <select class="layui-select" name="usertype" id="identity">

                    {if $has_teacher_auther}
                    <option  value="teacher" {if isset($vo.usertype) and $vo.usertype eq 'teacher' } selected {/if}>{:lang('老师')}</option>
                    {/if}
                    <option  value="super"  {if isset($vo.usertype) and $vo.usertype eq 'super' } selected {/if}>{:lang('超管')}</option>
                    <option  value="account" {if isset($vo.usertype) and $vo.usertype eq 'account' } selected {/if}>{:lang('其他')}</option>

                </select>
            </div>
        </div>

        <div class="layui-col-md12">
            <label class="layui-form-label">{:lang("登陆账号")}:</label>
            <div class="layui-input-block">

                <input name="username" value='{$vo.username}' required class="layui-input " placeholder="{:lang('请输入登陆账号')}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:lang("密码")}:</label>
            <div class="layui-input-block" >
                <input name="password" value=''  class="layui-input " placeholder="{:lang('如果不修改请留空')}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label label-required-next">{:lang("角色")}:</label>
            <div class="layui-input-block checkbox-role">

                {foreach $auth_arr as $key => $title}
                <input type="checkbox" name="authorize[]" title="{$title}" value="{$key}" lay-skin="tag" {if in_array($key, $vo.authorize)} checked {/if}>
                {/foreach}

            </div>
        </div>
    </div>
    <div class="hr-line-dashed"></div>
    <input type="hidden" value="{$vo.id}" name="id">

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>{:lang('保存数据')}</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="{:lang('确定要取消编辑吗')}？" data-close>{:lang('取消编辑')}</button>
    </div>
</form>
<script>
    form.on('select(account)', function (data) {
        let account_id = data.value;
        get("{:sysuri('getRoleList')}", {'account_id':account_id}, function (res) {

            let data = res.data;
            let html = '';
            for (let i in data) {
                html +='<input type="checkbox" name="authorize[]" title="'+ data[i] +'" value="'+ i +'" lay-skin="tag" >';
            }

            $('.checkbox-role').html(html);
            form.render('checkbox');
        })
        // 获得身份信息
        get("{:sysuri('common/ajax/getUserIdentity')}", {'account_id':account_id}, function (res) {

            let data = res.data;

            let select  = document.getElementById('identity');
            let options = select.getElementsByTagName('option');

            let is_has = false;
            let j = 0;
            for (let i = 0; i < options.length; i++) {
                if (options[i].value === 'teacher') {
                    //
                    j = i;
                    is_has = true;
                    break;
                }
            }

            if (data['identity']) { // 如果需要有 老师 这个选项
                // 判断是否有老师选项 有的话 不操作 没有的话添加
                if (is_has === false ) {
                    $('.layui-select').append('<option  value="teacher">{:lang("老师")}</option>')
                    form.render($('#identity'));
                }
            } else {
                // 如果有老师选项  删除
                if (is_has === true ) {
                    select.remove(j);
                    form.render($('#identity'));
                }
            }
        })
    });
</script>